import axios from 'axios'

const http = ({
                method,
                url,
                params
              }) => {
  return new Promise((resolve, reject) => {
    let authorization = JSON.parse(localStorage.getItem("token"))
    if (method === 'post' || method === 'Post' || method === 'POST') {
      axios.post(window.globalConfig.baseUrl + url, params, {
        headers: {
          'Authorization': authorization
        }
      }).then((res) => {
        resolve(res.data);
      }).catch((err) => {
        reject(err);
      })
    } else {
      axios.get(window.globalConfig.baseUrl + url, {
        params: params,
        headers: {'Authorization': authorization}
      }).then((res) => {
        resolve(res.data);
      }).catch((err) => {
        reject(err);
      })
    }
    // axios({
    //   url: window.globalConfig.baseUrl + url,
    //   headers: headers,
    //   params: params,
    //   method: method
    // }).then((res) => {
    //   resolve(res.data)
    // }).catch((err) => {
    //   reject(err);
    // })
  })
}
export default http;
